<template>
<el-select
  v-model="myValue"
  v-bind="$attrs"
  v-on="$listeners">
  <el-option
    v-for="item in generateOptions(options)"
    :key="item.code"
    :label="item.dictName"
    :disabled="item.disabled"
    :value="item.code"></el-option>
</el-select>
</template>

<script>
export default {
  name: "YCodeSelect",
  model:{
    prop: 'value',
    event: 'change'
  },
  inject: ['getDict'],
  props:{
    value: {},
    dict: String,
    disabledValue: [Array, String]
  },
  computed:{
    myValue:{
      get(){
        return this.value;
      },
      set(val){
        this.$emit('change:value', val);
      }
    }
  },
  asyncComputed:{
    options(){
      return this.getDict(this.dict);
    },
  },
  methods:{
    generateOptions(option){
      option = option || [];
      return option.map(item => {
        if(this.disabledValue){
          let dValue = this.disabledValue;
          if(typeof this.disabledValue === 'string'){
            dValue = dValue.split(',');
          }
          if(dValue.includes(item.code)){
            this.$set(item, 'disabled', true);
          }
        }
        return item;
      });
    }
  }
}
</script>

<style scoped>

</style>
